package com.cmpe451.nutty.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class LoginUtils {

	@Value("${PASSWORD_HASH_SECURE_KEY}")
	private String passwordHashSecureKey;

	public String generatePasswordHash(String originalPassword) {
		String first16 = passwordHashSecureKey.substring(0, 16);
		String last16 = passwordHashSecureKey.substring(16);

		StringBuilder sb = new StringBuilder(first16);
		sb.append(DigestUtils.md5Hex(originalPassword));
		sb.append(last16);
		return DigestUtils.md5Hex(sb.toString());
	}
}
